package model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.Id;

/**
 * <p>
 * Title: Vertex</p>
 * <p>
 * Description: CS 343 Project. Stores the vertices pointData model.</p>
 *
 * @date 11/18/2013
 *
 * @author Dylan Ahmann
 * @author Gregg Roemhildt - Class Programming and Javadocs
 * @author Sam Brockmann - Javadocs
 * @author Emily Hancock
 * @author Shirin Asadi
 *
 *
 * @param <T> type of pointData stored in Vertices
 */
//@Entity
public class Vertex<T extends Serializable> implements Serializable {

    protected T pointData;
//    @Id
    private String name;
    private List<Edge<T>> edges;

    /**
     * default constructor Sets everything to null or 0
     *
     */
    public Vertex() {
        pointData = null;
        name = "";
        edges = null;
    }

    /**
     * constructor Initializes pointData, name, and edges.
     *
     * @param d Vertex pointData
     * @param n Vertex name
     *
     */
    public Vertex(T d, String n) {
        edges = new ArrayList<>();
        pointData = d;
        name = n;
    }

    /**
     * copy constructor performs deep copy
     *
     * @param v set of Vertices
     */
    public Vertex(Vertex<T> v) {
        edges = new ArrayList<>();
        pointData = v.pointData;
        name = v.name;
        for (Edge<T> e : v.edges) {
            edges.add(e);
        }
    }

    /**
     * getData - a getter for this Vertex's pointData
     *
     * @return pointData
     */
    public T getPointData() {
        return pointData;
    }

    /**
     * getName - a getter for the name of this Vertex
     *
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * toString - a toString method for Vertex class
     *
     * @return String
     */
    @Override
    public String toString() {
        return this.name;
    }

    /**
     * addEdge Adds an Edge to the set of edges.
     *
     * @param e the Edge to add
     *
     */
    public void addEdge(Edge<T> e) {
        getEdges().add(e);
    }

    /**
     * getEdges Gets all the edges.
     *
     * @return edges
     *
     */
    public List<Edge<T>> getEdges() {
        return edges;
    }

    /**
     *
     * @param v
     * @return true if equal, false if not
     */
    public boolean equals(Vertex v) {
        return this.pointData == v.pointData;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

}
